package com.users.service.impl;

import java.util.List;

import com.users.bean.Users;
import com.users.dao.UsersDao;
import com.users.service.UsersService;
import com.users.util.MD5Encryption;
import com.users.util.PaginationSupport;

public class UsersServiceImpl implements UsersService{
	private UsersDao usersDao;
	public void setUsersDao(UsersDao usersDao) {
		this.usersDao = usersDao;
	}

	/**
	 * 通过用户名和密码获取用户信息
	 * @param userName 用户名
	 * @param passWord 用户密码
	 * @return 用户信息
	 */
	public Users getUsersByUserNameAndPassWord(String userName, String passWord) {
		return usersDao.getUsersByUserNameAndPassWord(userName, passWord);
	}

	/**
	 * 新增用户
	 * @param users
	 * @return
	 */
	public int addUsers(Users users) {
		if (users.getPassWord() != null && !"".equals(users.getPassWord())) {
			users.setPassWord(MD5Encryption.stringToMD5(users.getPassWord()));// MD5加密存储密码
		}
		return usersDao.addUsers(users);
	}

	/**
	 * 删除用户
	 * @param users
	 * @return
	 */
	public int delUsers(Users users) {
		return usersDao.delUsers(users);
	}
	/**
	 * 分页查询所有用户
	 * @param pageSize 每页条数
	 * @param startIndex 开始页数
	 * @param keyValue
	 * @param users
	 * @return
	 */
	public PaginationSupport queryUsersByPage(final int pageSize, final int startIndex, final Users users) {
		return usersDao.queryUsersByPage(pageSize, startIndex, users);
	}

	/**
	 * 
	 * @param UserName
	 * @return
	 */
	public List<String> queryUserName(String UserName) {
		return usersDao.queryUserName(UserName);
	}

	/**
	 * 查询所有用户
	 * @return
	 */
	public List<Users> queryUserList() {
		return usersDao.queryUserList();
	}
}
